﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using ContractManagermentSystem.Business;
using ContractManagermentSystem.Entity;

namespace ContractManagermentSystem.Pages
{
    public partial class CreateContractor : System.Web.UI.Page
    {
        private readonly ContractorBus _contractorBus = new ContractorBus();

        protected void PageLoad(object sender, EventArgs e)
        {

        }

        protected void CreateButtonClick(object sender, EventArgs e)
        {
            var contractor = new Contractor();
            contractor.Username = UserName.Text;
            contractor.Password = Password.Text;
            contractor.FullName = FullName.Text;
            contractor.PhoneNumber1 = PhoneNumber1.Text;
            contractor.PhoneNumber2 = PhoneNumber2.Text;
            contractor.Gender = Gender.SelectedValue;
            contractor.IsActive = IsActive.Checked;
            contractor.Branch = Branch.Text;
            contractor.SortCode = SortCode.Text;

            int check = _contractorBus.CheckUserName(contractor.Username);
            if (check == 0)
            {
                _contractorBus.CreateContractor(contractor);
                Response.Redirect("ContractorManagement.aspx");
            }
            else
            {

            }
        }

        protected void ResetButtonClick(object sender, EventArgs e)
        {
            UserName.Text = null;
            Password.Text = null;
            FullName.Text = null;
            PhoneNumber1.Text = null;
            PhoneNumber2.Text = null;
            IsActive.Checked = false;
            Branch.Text = null;
            SortCode.Text = null;
        }
    }
}
